package com.example.role_based_permission_control.config;

import com.example.role_based_permission_control.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 李云龙
 * @program: role_based_permmsion_control
 * @description: 注册拦截器
 * @date 2024-09-01 16:14:02
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private AuthInterceptor authInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns("/login") // 排除登录接口
                // 以下是 Swagger 相关路径
                .excludePathPatterns("/swagger-resources/**", "/swagger-ui.html", "/v2/api-docs", "/webjars/**");
    }
}
